import React, { Component } from 'react'
const { v4: uuidv4 } = require('uuid');

module.exports = function (options) {
  const handleLogin = () => {
    const { authUrl, callbackUrl, clientId, scope } = options;
    let redirectURL = authUrl  + '?client_id=' + clientId 
      + '&scope=' + scope 
      + '&response_type=code'
      + '&state=' + uuidv4()
      + '&redirect_uri=' + encodeURIComponent(callbackUrl);
    location.href = redirectURL;
  }

  const OIDCLoginComponent = () => (
    <button onClick={handleLogin} className="btn-home btn-home-normal" >OIDC登录</button>
  )

  this.bindHook('third_login', OIDCLoginComponent);
};
